﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>创建盘点任务(暂时没用着)</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/Content/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/Content/X-admin/lib/layui/layui.js"></script>
    <link href="~/Content/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/Content/X-admin/js/jquery.min.js"></script>
    <script src="~/Content/X-admin/js/xadmin.js"></script>
    <script src="~/Content/Scripts/Basis/UserJs.js"></script>
    <script src="~/Content/Scripts/System/systemFrame.js"></script>
    <script src="~/Content/Scripts/System/Common.js"></script>


</head>
<body>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5" name="qForm" id="qForm">
                            <div class="layui-inline layui-show-xs-block">
                                <input class="layui-input" placeholder="开始日期" name="sDate" id="sDate" style="width:130px;">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input class="layui-input" placeholder="结束日期" name="eDate" id="eDate" style="width: 130px;">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="s.cCVCode" placeholder="盘点单号" autocomplete="off" class="layui-input" id="s.cCVCode" style="width: 130px;">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="s.cInvCode" placeholder="存货编码" autocomplete="off" class="layui-input" id="s.cInvCode" style="width: 130px;">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="p.cInvName" placeholder="存货名称" autocomplete="off" class="layui-input" id="p.cInvName" style="width: 150px;">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="w.cWhName" placeholder="仓库名称" autocomplete="off" class="layui-input" id="w.cWhName" style="width: 130px;">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="po.cPosName" placeholder="货位名称" autocomplete="off" class="layui-input" id="po.cPosName" style="width: 130px;">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn" lay-filter="sreach" id="btn-view" type="button" onclick="TaskTable()"><i class="layui-icon">&#xe615;</i></button>
                            </div>
                        </form>

                    </div>
                    <div class="layui-card-header">
                        @*@if (ViewData["operate"].ToString().Contains("addTask"))*@
                        <button class="layui-btn" id="barAdd" type="button" onclick="createTask()"><i class="layui-icon"></i>创建任务</button>
                        <span style="margin-left: 20px; padding: 7px; background-color: #A6FFFF; font-size: Xx-small">盘点中</span>

                    </div>
                    <div class="layui-card-body layui-table-body" id="layui-table-main">
                        <table class="layui-hide" id="task" lay-filter="task"></table>
                    </div>


                </div>
                </div>
        </div>
    </div>
</body>

</html>

<script>
    var currPage = 1;//首先默认值为1，防止出错
    var list = [];
    var vCodes = "";
    /**
    ERP盘点任务单
    **/
    function TaskTable() {
        layui.use('table', function () {
            var table = layui.table;
            var conditon = JSON.stringify(FormToJson("qForm"));
            table.render({
                elem: '#task'
            , cols: [[ //标题栏
                { type: 'checkbox'}
              , { field: 'code', title: '盘点单号', width: 100 }
                , { field: 'proName', title: '盘点存货', width: 150 }
                , { field: 'proCode', title: '存货编码', width: 100 }
                , { field: 'color', title: '颜色', width: 100 }
                , { field: 'shangbiao', title: '商标', width: 100 }
                , { field: 'spec', title: '规格', width: 100 }
                , { field: 'wareName', title: '仓库名称', width: 130 }
                , { field: 'wareCode', title: '仓库编码', width: 100 }
                , { field: 'positionName', title: '仓库货位', width: 120 }
                , { field: 'positionCode', title: '货位编码', width: 100 }
              , { field: 'number', title: '账面数量', width: 110 }
            ]], done: function (res, curr, count) {
                $("[data-field='id']").css('display', 'none');//隐藏列
                currPage = curr;
                $.each(res['data'], function (i, j) {
                    if (j['isColor'] == "1") {
                        TableRowColor('layui-table-main', i, '#CAFFFF');//处理中
                    }
                });
            }
                , url: "../ProCheck/GetDataList?dataType=erptask&condition=" + conditon
            , skin: 'row' //表格风格
                , even: true
                , page: false //是否显示分页
            , limits: [20, 30, 50]
            , limit: 20 //每页默认显示的数量
            , id: "tData"
            });
        
            //监听工具条
            table.on('checkbox(task)', function (obj) {
                var checkStatus = table.checkStatus('tData');
                var datas = checkStatus.data;
                list = [];
                for (var i = 0; i < datas.length; i++) {
                    var obj = new Object();
                    obj.erpCode = datas[i].code
                    obj.erpProCode = datas[i].proCode;
                    obj.color = datas[i].color;
                    obj.shangbiao = datas[i].shangbiao;
                    obj.erpWareCode = datas[i].wareCode;
                    obj.erpPositionCode = datas[i].positionCode;
                    obj.erpNumber = datas[i].number;
                    obj.erpId = datas[i].erpId;
                    list.push(obj);
                }
            });
        });
    }
    $(function () {
        $("input[ name='sDate']").val(getDate(-30));
        $("input[ name='eDate']").val(getDate(0));
        TaskTable();
    })

    layui.use(['laydate'], function () {
        var $ = layui.$;
        var laydate = layui.laydate;
        var nowTime = new Date().valueOf();
        var max = null;
        var start = laydate.render({
            elem: '#sDate',
            trigger: 'click',
            type: 'date',
            format: 'yyyy-MM-dd',
            max: nowTime,
            btns: ['clear', 'confirm'],
            done: function (value, date) {
                endMax = end.config.max;
                end.config.min = date; //最大时间为结束时间的开始值
                end.config.min.month = date.month - 1;
            }
        });
        var end = laydate.render({
            elem: '#eDate',
            trigger: 'click',
            type: 'date',
            max: 4073558400000,
            format: 'yyyy-MM-dd',
            done: function (value, date) {
                if ($.trim(value) == '') {
                    var curDate = new Date();
                    date = { 'date': curDate.getDate(), 'month': curDate.getMonth() + 1, 'year': curDate.getFullYear() };
                }
                start.config.max = date;//最小时间为开始时间的最大值
                start.config.max.month = date.month - 1;
            }
        })
    })

    /**
    创建盘点任务
    **/ 
    function createTask() {
        if (list.length < 1) {
            layer.msg("请先选择数据"); return;
        }
        if (list.length > 20) {
            layer.msg("选择数据太多了(最多20)"); return;
        }
                var loadwin = layer.load(2, {
                    shade: [0.3, '#424242'],
                    content: '生成中',
                    success: function (layerContentStyle) {
                        layerContentStyle.find('.layui-layer-content').css({
                            'padding-top': '35px',
                            'text-align': 'left',
                            'width': '120px'
                        });
                    }
                }, { shadeClose: true });
                $.ajax({
                    url: '../ProCheck/CreateTask',
                    data: { datas: JSON.stringify(list) },
                    dataType: "json",
                    type: "POST",
                    success: function (data) {
                        if (data.Result) {
                            layer.msg("盘点任务创建成功");
                            TaskTable();
                        } else {
                            layer.msg(data.Message);
                        }
                        layer.close(loadwin);
                    }
                });
         

    }

</script>